package com.orange.agent.rebangTody.consumer;

import com.orange.agent.rebangTody.RebangURLEnum;
import com.orange.agent.rebangTody.model.RebangDataReq;
import com.orange.agent.rebangTody.model.RebangSuperReq;
import com.orange.common.base.httpConfig.HttpAPIService;
import com.orange.common.utils.ConvertUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * 发起Http请求业务逻辑
 *
 * @Author YWF
 * @Date 2025/9/3 15:40
 */
@Component
@Slf4j
public class RebangHttpConsumer extends AbstractRebangConsumer {

    @Autowired
    protected HttpAPIService httpAPIService;

    @Override
    protected String dataCommit(String transCode, RebangDataReq<RebangSuperReq> request) {

        RebangURLEnum urlEnum = RebangURLEnum.getByTransCode(transCode);
        String body = "";
        try {
            RebangSuperReq param = request.getData();
            String url = urlEnum.getUrl();
            Map<String, Object> objectMap = ConvertUtils.objectToMap(param);
            log.info("Rebang Today 获取参数：{}", objectMap);
            body = httpAPIService.doGet(url, objectMap);
        } catch (Exception e) {
            log.error("Rebang Today 平台网络请求失败-->交易码：{}，交易接口：{}-->{}", transCode, urlEnum.getDescribe(), e.getMessage());
        }
        log.info("热点新闻查询结果：{}", body);
        return body;
    }
}
